import { configureStore } from '@reduxjs/toolkit'
import { TypedUseSelectorHook, shallowEqual, useDispatch, useSelector } from 'react-redux'

import homeReducer from './module/home'
import optionsReducer from './module/options'
import shareReducer from './module/share'
import productReducer from './module/product'

export const store = configureStore({
  reducer: {
    home: homeReducer,
    options: optionsReducer,
    share: shareReducer,
    product: productReducer,
  }
})

type GetStateFnType = typeof store.getState
type IRootState = ReturnType<GetStateFnType>
type AppDispatch = typeof store.dispatch

export const useAppSelector: TypedUseSelectorHook<IRootState> = useSelector
export const useAppDispatch: () => AppDispatch = useDispatch
export const shallowEqualApp = shallowEqual
